Providers
Providers connect BindAI agents to language models. BindAI separates agent configuration from the underlying model provider so applications can select different providers without changing the overall agent architecture. The provider layer defines a common interface for model generation and streaming, while provider-specific packages implement communication with individual model services.Provider Architecture
The relationship between an application, agent, provider, and model can be represented as:- Provider name
- Model generation
- Streaming
- Provider capabilities
- Provider configuration
Supported Providers
The current BindAI provider configuration and bootstrap system recognizes:- OpenAI
- Anthropic
- Groq
- Ollama
- OpenRouter
bindai-core.
Configuring a Model
The recommended way to select a model is throughAgent.builder().
Provider-Qualified Models
Provider-qualified model names allow the application to select a provider and model through a single configuration value. For example:Provider Configuration
Providers receive a commonProviderConfiguration object.
The configuration contains:
api_key— provider authentication credential.endpoint— provider or service endpoint.organization— provider organization identifier when applicable.model— selected model identifier.timeout— request timeout in seconds; the default is60.headers— additional request headers.
Environment Variables
Provider credentials should not be hardcoded into application source code. The BindAI provider configuration layer recognizes environment variables for the supported providers. For example:Project-Scoped Provider Connections
BindAI can also select provider credentials through named project-scoped connections. For example:- Explicitly supplied API key.
- Credential stored for the selected project connection.
- Provider environment variable.
Provider Interface
The canonical provider abstraction isModelProvider.
A provider implementation receives a ProviderConfiguration and implements:
generate()for normal model execution.stream()for streaming model execution.
capabilities property describes the features exposed by the provider implementation.
Provider Capabilities
BindAI represents provider capabilities throughProviderCapabilities.
The capability model includes:
chatstreamingvisionembeddingstool_callingstructured_outputreasoning
Provider Registry
BindAI exposesProviderRegistry for provider registration and discovery.
For example:
- Registering providers
- Unregistering providers
- Checking whether a provider exists
- Retrieving a provider
- Creating a provider
- Listing registered providers
- Clearing registrations
bindai-providers acts as a compatibility facade over the canonical ProviderFactory in bindai-core.
This keeps provider creation consistent with the core provider architecture.
Provider Bootstrap
BindAI initializes supported provider integrations through provider bootstrap. The bootstrap process attempts to load the provider modules for the supported provider integrations:OpenAI
OpenAI models can be selected using theopenai provider prefix.
Anthropic
Anthropic models can be selected using theanthropic provider prefix.
Google Gemini
Google Gemini models can be selected using thegoogle provider prefix.
Groq
Groq models can be selected using thegroq provider prefix.
Ollama
Ollama models can be selected through theollama provider prefix.
OpenRouter
OpenRouter models can be selected through theopenrouter provider prefix.
Provider and Agent Configuration
Provider configuration and agent behavior are separate concerns. For example:model()selects the provider and model.instructions()defines agent behavior.build()creates the configured agent.
Switching Providers
Because the model is configured through the agent builder, changing providers can often be as simple as changing the model string. For example:Provider and Tools
Providers work together with BindAI’s tool system. For example:Provider and Structured Output
BindAI agents can request structured output throughrun().
For example:
Provider and Streaming
The provider interface includes astream() operation for streaming model output.
At the agent level, applications can use:
streaming flag indicating whether streaming is supported by the provider implementation.
Streaming is useful for:
- Chat interfaces
- Interactive applications
- Long responses
- Real-time user experiences
Provider and Memory
Memory is implemented at the BindAI agent/application layer rather than being tied to a particular model provider. For example:Provider and Knowledge
Knowledge and retrieval are also separate from the provider implementation. For example:Local Models
The provider abstraction allows applications to use local inference services. For example:Custom Providers
BindAI’s provider architecture is designed around theModelProvider abstraction and the core provider registry.
A custom provider implementation needs to provide the common provider operations:
ProviderConfiguration and can expose its supported capabilities through ProviderCapabilities.
Providers can then be registered with the provider registry.
Because provider APIs and registration mechanisms can evolve independently, custom provider implementations should follow the interfaces exposed by the BindAI version being used.
Provider Independence
Provider independence means that the application-level agent interface is separated from provider-specific model communication. For example:Provider Portability
The provider-qualified model format allows the same general agent architecture to be used with different providers. For example:- Tool calling
- Structured output
- Streaming
- Vision
- Embeddings
- Reasoning
- Particular context limits
- Provider-specific features
Choosing a Provider
The appropriate provider depends on the application’s requirements. Consider:- Model capabilities
- Hosting requirements
- Privacy requirements
- Latency
- Cost
- Tool-calling support
- Structured-output support
- Streaming support
- Deployment environment
- Local versus hosted inference
Provider Configuration in Development
A typical development environment can keep provider credentials in a.env file.
For example:
.env file when it contains real credentials.
A project can also configure only the provider credentials it actually needs.
For project-scoped provider credentials, BindAI can store connection credentials in the operating system credential store instead of placing them in .env or bindai.toml.
Provider Errors
Provider execution can fail for reasons such as:- Invalid credentials
- Missing credentials
- Unsupported model
- Provider service errors
- Network failures
- Rate limits
- Invalid requests
- Provider account or quota restrictions
Provider Testing
Provider integrations should be tested independently as well as through agent execution. Useful tests include:- Provider registration
- Provider discovery
- Provider creation
- Authentication configuration
- Model generation
- Streaming
- Tool calling when supported
- Structured output when supported
- Capability reporting
- Error handling
Complete Example
A complete agent can use the provider abstraction together with other BindAI capabilities:Best Practices
- Keep provider credentials out of source code.
- Use environment variables, project-scoped connections, or an appropriate secret-management system for credentials.
- Use the
provider:modelformat when selecting a model. - Prefer
Agent.builder()for agent configuration. - Keep provider-specific logic out of application-level business logic where practical.
- Verify provider/model capabilities before relying on tool calling or structured output.
- Test provider/model combinations used by the application.
- Use local providers when local inference is appropriate.
- Choose models based on the actual requirements of the task.
- Keep provider configuration separate from agent instructions whenever possible.
- Do not assume that different providers will produce identical behavior.
- Check the provider capability metadata when an application depends on a specific feature.
- Keep provider integrations modular so additional providers can be added without changing the core agent abstraction.
